package com.ruoyi.cms.controller.portal;

import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.ruoyi.cms.service.DashScopeService;
import com.ruoyi.common.annotation.AllowAnonymous;
import io.reactivex.Flowable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * AI
 */
@RestController
@RequestMapping("/portal/cms/dashScope")
public class DashScopeController {

    @Autowired
    private DashScopeService dashScopeService;

    /**
     * 直接输出
     */
    @PostMapping("/call")
    @AllowAnonymous
    public GenerationResult call(@RequestBody String message) {
        return dashScopeService.call(message);
    }

    /**
     * 流式输出
     */
    @PostMapping(value = "/streamCall", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
    @AllowAnonymous
    public Flowable<GenerationResult> streamCall(@RequestBody String message) {
        return dashScopeService.streamCall(message);
    }

}
